#define  _CRT_SECURE_NO_WARNINGS
class MedianFinder {
public:
    MedianFinder() {

    }

    void addNum(int num) {
        if (++count & 1)
        {
            if (L.size() && num < L.top()) mid = L.top(), L.pop(), L.push(num);
            else if (G.size() && num > G.top()) mid = G.top(), G.pop(), G.push(num);
            else mid = num;
        }
        else
        {
            L.push(mid);
            L.push(num);
            while (L.size() != G.size()) G.push(L.top()), L.pop();
        }
    }

    double findMedian() {
        return (count & 1) ? mid : L.top() / 2.0 + G.top() / 2.0;
    }
private:
    int count = 0;
    int mid = 0;
    priority_queue<int, vector<int>, less<int>> L;
    priority_queue<int, vector<int>, greater<int>> G;
};

/**
 * Your MedianFinder object will be instantiated and called as such:
 * MedianFinder* obj = new MedianFinder();
 * obj->addNum(num);
 * double param_2 = obj->findMedian();
 */